package com.budayi;

import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.util.stream.Collectors;

/**
 * @author LIBOFEI
 * @ClassName com.budayi.SystemServiceApplication
 * @description 系统服务启动类
 * @date 2021/4/20 17:36
 * @Version 1.0
 **/
@SpringBootApplication(scanBasePackages= {"com.budayi.*"},exclude = {MultipartAutoConfiguration.class})//启动
@MapperScan({"com.budayi.dao"})//Mapper扫包
@EnableDiscoveryClient//服务发现
@EnableFeignClients//开启FeignClient的功能 远程调用其他服务
@EnableAsync//异步执行
public class SystemServiceApplication  extends SpringBootServletInitializer {


    private static final Logger logger = LoggerFactory.getLogger(SystemServiceApplication.class);

    public static void main(String[] args) {
        SpringApplication.run(SystemServiceApplication.class, args);
    }


    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        logger.info("system init");
        return application.sources(SystemServiceApplication.class);
    }

    /** *
     openfeign调用显示没有转化器
     **/
    @Bean
    @ConditionalOnMissingBean
    public HttpMessageConverters messageConverters(ObjectProvider<HttpMessageConverter<?>> converters) {
        return new HttpMessageConverters(converters.orderedStream().collect(Collectors.toList()));
    }
}
